package indi.woniu.controller;

import com.github.pagehelper.PageInfo;
import indi.woniu.entity.Pool;
import indi.woniu.entity.ResponseEntity;
import indi.woniu.service.PoolService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.net.URLDecoder;
import java.util.List;

/**
 * @author: wgt
 * Date: 2021/12/15:14:42
 * Description:题库分类
 */
@CrossOrigin
@RestController
@RequestMapping("/pool")
public class PoolController {
    @Autowired
    PoolService poolService;
    @PostMapping("/findAll/{page}/{limit}")
    //分页查询
    public ResponseEntity findAll(@PathVariable int page, @PathVariable int limit){
        ResponseEntity all = poolService.findAll(page, limit);
        return all;
    }
    //模糊查询
    @PostMapping("/findByName/{name}")
    public ResponseEntity findByName(@PathVariable String name){
        return poolService.findByName(name);
    }
    //子题库查询
    @PostMapping("/findSonPool/{page}/{limit}")
    public ResponseEntity findSonPool(@PathVariable int page,@PathVariable int limit ,@RequestBody Pool pool){

        ResponseEntity byType = poolService.findByType(page, limit, pool);
        System.out.println(byType.getData());
        return byType;

    }
    //新增题库
    @RequestMapping("/move")
    public ResponseEntity  fMovePool(@RequestBody Pool pool){
        ResponseEntity movePool = poolService.findByName(pool.getPoolName());

        System.out.println(movePool);
       return poolService.fMovePool(pool);

    }
    //修改题库
    @RequestMapping("/update")
    public ResponseEntity updatePool(@RequestBody Pool pool){
        return   poolService.updatePool(pool);
    }
   //删除题库
    @PostMapping("/delete/{id}")
    public ResponseEntity deletePoolById(@PathVariable int id) {
        return  poolService.deletePoolById(id);

    }

    @RequestMapping( "/findfpool" )
    //查询所有父体库
    public ResponseEntity findFPool(){
      return   poolService.findFpool();

    }
    //根据父题库关键字查找子题库
    @RequestMapping("/findspool")
    public ResponseEntity findSPool(@RequestBody String poolName){
      return   poolService.findSpool(poolName);
    }
    //无条件查询所有子题库
    @RequestMapping("/findspools")
    public ResponseEntity findsPools(){
        return   poolService.findSpools();
    }
    //根据父库名称查找父id
    @PostMapping ("/findidPool/{poolName}")
    public ResponseEntity findSFPool(@PathVariable String poolName){
//        String jsonObject = URLDecoder.decode(poolName, "utf-8");
        return poolService.findSFPool(poolName);
    }

    //根据fid查找到当前的父库id下的所有子库
    @RequestMapping("/findFidPool")
    public ResponseEntity findFidPool(@RequestBody Pool pool){

        return  poolService.findFidPool(pool);
    }

//    新新增父题库
@RequestMapping("/insertFpool")
    public ResponseEntity fpool(@RequestBody Pool pool){
    return  poolService.insertFpool(pool);





    }
//    新新增子题库
    @RequestMapping("/insertSpool")
    public ResponseEntity spool(@RequestBody Pool pool){
        return    poolService.insertSpool(pool);

    }

    //子题库模糊查询
    @RequestMapping("/findSonPoolName")
    public ResponseEntity findSonPoolName(@RequestBody Pool pool){
        return    poolService.findSonPoolName(pool);

    }
    //无条件查询所有题库
    @PostMapping(value = "/findAllAll/{page}/{limit}")
    public ResponseEntity findAllAll(@PathVariable int page, @PathVariable int limit){
        return   poolService.findAllAll(page,limit);

    }
    //模糊查询所有题库
    @RequestMapping("/findAllAllByName")
    public ResponseEntity findAllAllByName(@RequestBody Pool pool) {
        return poolService.findAllAllByName(pool);
    }


    //根据父id和关键字查询子库
    @RequestMapping("/findByFidAndSunName")
    public ResponseEntity findByFidAndSunName(@RequestBody Pool pool) {

        return poolService.findByFidAndSunName(pool);
    }


}
